var game = new function() {
  this.createPiece = function (game_id, piece_kind, piece_value, callback) {
    $.ajax({
      url : "/game/create_piece?id=" + game_id +
        "&piece_kind=" + piece_kind + "&piece_value=" + piece_value,
      type : "POST",
      success : function() {
        if (callback) {
          callback();
        } else {
          window.location.reload(true);
        }
      }
    });
  };

  this.deletePiece = function (piece_kind, piece_id, callback) {
    $.ajax({
      url : "/game/delete_piece?piece_kind=" + piece_kind + "&piece_id=" + piece_id,
      type : "POST",
      success : function() {
        if (callback) {
          callback();
        } else {
          window.location.reload(true);
        }
      }
    });
  };

  this.savePieceProperty = function(piece_kind, piece_id, property_name, property_value, callback) {
    $.ajax({
      url : "/game/save_piece_property?piece_kind=" + piece_kind + "&piece_id=" + piece_id +
        "&property_name=" + property_name + "&property_value=" + property_value,
      type : "POST",
      success : function() {
        if (callback) {
          callback();
        } else {
          window.location.reload(true);
        }
      }
    });
  };

  this.deleteGame = function(name, type, id, callback) {
    if (!confirm("Are you sure you want to delete '" + name + " (" + type + ")' ?")) {
      return;
    }
    $.ajax({
      url : "/game/delete?id=" + id,
      type : "POST",
      success : function() {
        if (callback) {
          callback();
        } else {
          window.location.reload(true);
        }
      }
    });
  };
};